(function(){
	var Page = {
		init:function(){
			this.render();
			this.event();
		},
		//绑定事件
		event:function(){
		  //下载模板
		  $(".loadEXCEL").click(function(){
			  var fileExport = 'http://web.icecn.net/user/downloadExcelModel.json';
			  location.href = fileExport;
		  })
		  //手动添加
		  $(".btnsave").click(function(){
			 var ids=$("#ids").val(); 
			 var currency=$("#currency").val(); 
			 var value=$("#value").val(); 
			 var reason=$("#reason").val(); 
			 if(ids==""){alert("请输入账号");return}
			 if(value==""){alert("请输入金额");return}
			 $.ajax({
				url:'http://web.icecn.net/user/importWebWealthHand.json',
				type:'POST',
				async:true,
				data:{
					ids:ids,
					currency:currency,
					value:value,
					reason:reason
				},
				dataType: "json",
				xhrFields:{withCredentials:true},
				success: function(data){
					if(data.code === 200 ){
						alert("添加成功")
						window.location.reload()
					}else{
						alert(data.msg)
					}
				}
		     });
		  })
		  //excel导入
		  $("#lefileexcel").change(function(){
				var fileObj =document.getElementById("lefileexcel").files[0];
				$.ajax({
					url:'http://39.106.145.173:8087/leveling/getToken.json',
					type:'POST',
					async:true,
					data:{
					},
					dataType: "json",
					success: function(data){
						var form = new FormData;
						form.append("file",fileObj);
						form.append("key",new Date().getTime()+".xls");
						form.append("token",data.t.token);
						var domian=data.t.domain;
						$.ajax({
							url:'http://up.qiniu.com',
							type: 'POST',
							data:form,
							async: false,
							cache: false,
							contentType: false,
							processData: false,
							dataType: "json",
							success: function(data) {
							   var url=""+domian+"/"+data.key+""
							   form.append("excelUrl",url);
							   $.ajax({
									url:'http://web.icecn.net/user/importWebWealthExcel.json',
									type:'POST',
									async:false,
									cache: false,
									contentType: false,
									processData: false,
									data:form,
									dataType: "json",
					                xhrFields:{withCredentials:true},
									success: function(data){
										if(data.code === 200 ){
											alert("导入成功")
										}else{
											alert(data.msg)
										}
									}
							   });
							   $("#lefileexcel").val("")
							},
						});	
					}
				});	
		  })
		},
		//渲染页面
		render:function(){
			
		}
	};
	Page.init();
})();